home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / Plug-in - Attr / QuickAttrTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  5.1 KB  |  210 lines  |  [TEXT/CWIE]

  1. /* real simple test program for the name plug-in attribute */
  2.  
  3. #define TEST_RADAR_ID_1401065 1
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. #include <CodeFragments.h>
  10. #include <Dialogs.h>
  11. #include <Fonts.h>
  12. #include <Memory.h>
  13. #include <QuickDraw.h>
  14. #include <StandardFile.h>
  15. #include <Windows.h>
  16.  
  17. #include "QD3D.h"
  18. #include "QD3DExtension.h"
  19. #include "QD3DGeometry.h"
  20. #include "QD3DGroup.h"
  21. #include "QD3DIO.h"
  22. #include "QD3DMath.h"
  23. #include "QD3DStorage.h"
  24.  
  25.  
  26. #include "NameAttribute.h"
  27.  
  28. static void InitToolbox(void) ;
  29.  
  30.  
  31.  
  32. /* initialize the Mac toolbox */
  33. static void InitToolbox(void)
  34. {
  35.  
  36.     MaxApplZone() ;
  37.     MoreMasters() ; MoreMasters() ; MoreMasters() ; 
  38.     
  39.     InitGraf( &qd.thePort );
  40.     InitFonts();
  41.     InitWindows();
  42.  
  43.     FlushEvents( everyEvent, 0 ) ;
  44.  
  45.     InitCursor();
  46. }
  47.  
  48.  
  49. static TQ3GroupObject BuildTriangle(
  50.     void)
  51. {
  52.     TQ3ColorRGB            triangleColor;
  53.  
  54.     TQ3GroupObject        model;
  55.     TQ3TriangleData        triangleData;
  56.     TQ3GeometryObject    triangleThang;
  57.     static TQ3Vertex3D    vertices[3] = {
  58.                             { { -1.0, -0.5, -0.25 }, NULL },
  59.                             { {  0.0,  0.0,  0.0  }, NULL },
  60.                             { { -0.5,  1.5,  0.45 }, NULL },
  61.                         };
  62.  
  63.     triangleData.vertices[0] = vertices[0];
  64.     triangleData.vertices[1] = vertices[1];
  65.     triangleData.vertices[2] = vertices[2];
  66.     
  67.     triangleData.triangleAttributeSet = Q3AttributeSet_New();
  68.     triangleColor.r = 0.8;
  69.     triangleColor.g = 0.5;
  70.     triangleColor.b = 0.2;
  71.  
  72.     Q3AttributeSet_Add(
  73.         triangleData.triangleAttributeSet, 
  74.         kQ3AttributeTypeDiffuseColor, 
  75.         &triangleColor);
  76.  
  77.     triangleData.vertices[0].attributeSet = Q3AttributeSet_New();
  78.     triangleData.vertices[1].attributeSet = Q3AttributeSet_New();
  79.     triangleData.vertices[2].attributeSet = Q3AttributeSet_New();
  80.     triangleColor.r = 1.0;
  81.     triangleColor.g = 0.0;
  82.     triangleColor.b = 0.0;
  83.  
  84.     Q3AttributeSet_Add(
  85.         triangleData.vertices[0].attributeSet, 
  86.         kQ3AttributeTypeDiffuseColor, 
  87.         &triangleColor);
  88.  
  89.     triangleColor.r = 0.0;
  90.     triangleColor.g = 1.0;
  91.     triangleColor.b = 0.0;
  92.  
  93.     Q3AttributeSet_Add(
  94.         triangleData.vertices[1].attributeSet, 
  95.         kQ3AttributeTypeDiffuseColor, 
  96.         &triangleColor);
  97.  
  98.     triangleColor.r = 0.0;
  99.     triangleColor.g = 0.0;
  100.     triangleColor.b = 1.0;
  101.  
  102.     Q3AttributeSet_Add(
  103.         triangleData.vertices[2].attributeSet, 
  104.         kQ3AttributeTypeDiffuseColor, 
  105.         &triangleColor);
  106.  
  107.     triangleThang = Q3Triangle_New(&triangleData);
  108.     
  109.     model = Q3OrderedDisplayGroup_New();
  110.  
  111.     if (triangleThang != NULL) {
  112.         Q3Group_AddObject(model, triangleThang);    
  113.     
  114.         Q3Object_Dispose(triangleThang);
  115.     }
  116.     
  117.     Q3Object_Dispose(triangleData.vertices[0].attributeSet);
  118.     Q3Object_Dispose(triangleData.vertices[1].attributeSet);
  119.     Q3Object_Dispose(triangleData.vertices[2].attributeSet);
  120.     Q3Object_Dispose(triangleData.triangleAttributeSet);
  121.  
  122.     return (model);    
  123. }
  124.  
  125.  
  126. /* entry point */
  127. void main(void)
  128. {
  129.     TQ3Status         myStatus ;
  130.     TQ3GroupObject    myGroup ;
  131.     const short        length = 256 ;
  132.     char            myName[ length ] ;
  133.     char            *tempStr ;
  134.     const char        defaultName[] = "This is the name attribute string" ;
  135.     short            index = 0 ;
  136.     
  137.     InitToolbox() ;
  138.     if( (long)Q3Initialize != kUnresolvedCFragSymbolAddress )
  139.     {
  140.         printf( "Initializing QuickDraw 3D" ) ;
  141.         
  142.         if((myStatus = Q3Initialize()) == kQ3Success)
  143.         {
  144.             printf(" - successful\n" ) ;
  145.  
  146.             printf( "Making a test geometry" ) ;
  147.             
  148.             /* make a geometry object */
  149.             if((myGroup = BuildTriangle()) != NULL)
  150.             {
  151.                 TQ3XObjectClassVersion        myVersion ;
  152.                 TQ3ObjectType                 objectClassType ;
  153.                 printf(" - successful\n" ) ;
  154.                 
  155.                 /* try adding a name to it */                
  156.                 strcpy( myName, defaultName ) ;
  157.                 printf( "Adding String \"%s\" as name attribute to the group\n", myName ) ;
  158.                 NameAttribute_SetName( myGroup, myName ) ;
  159.                 
  160.                 /* zero out the string */
  161.                 for( index = 0; index < length; index++ )
  162.                     myName[ index ] = '\0' ;
  163.                 printf( "Zeroed String \"%s\"\n", myName ) ;
  164.  
  165.                 NameAttribute_GetName( myGroup, myName ) ;
  166.                 printf( "Got String \"%s\" from name attribute in the group\n", myName ) ;
  167.                 
  168.                 NameAttribute_GetName( myGroup, myName ) ;
  169.                 printf( "Got String \"%s\" from name attribute in the group\n", myName ) ;
  170.                 
  171.                 NameAttribute_GetName( myGroup, myName ) ;
  172.                 printf( "Got String \"%s\" from name attribute in the group\n", myName ) ;
  173.  
  174. #ifdef FORCE_TO_FAIL_TEST
  175.                 /*
  176.                  * You can't do this.  When the element type is registered QD3D 
  177.                  * modifies it and passes back a reference.  If you want to get 
  178.                  * the version number for a attribute or element, get the type
  179.                  * from the name and then use that type to get the version.  This
  180.                  * is illustrated below.
  181.                  */            
  182.                 Q3XObjectHierarchy_GetClassVersion kElementTypeName, &myVersion ) ;
  183. #else
  184.                 Q3ObjectHierarchy_GetTypeFromString(kElementTypeNameString, &objectClassType );
  185.                 Q3XObjectHierarchy_GetClassVersion( objectClassType, &myVersion ) ;
  186. #endif
  187.                 
  188.                 printf( "This is version %d.%d\n", 
  189.                             Q3_OBJECT_CLASS_GET_MAJOR_VERSION( myVersion ),
  190.                             Q3_OBJECT_CLASS_GET_MINOR_VERSION( myVersion ) );
  191.                 Q3Object_Dispose( myGroup ) ;
  192.                 
  193. #ifdef TEST_RADAR_ID_1401065
  194.                 if( NameAttribute_Unregister() == kQ3Failure )
  195.                     printf("NameAttribute_Unregister failed\n") ;
  196. #endif
  197.             }
  198.             else
  199.             {
  200.                 printf(" - failed\n" ) ;
  201.             }
  202.         }
  203.         else
  204.         {
  205.             printf(" - failed\n" ) ;
  206.         }
  207.          
  208.     }
  209. }
  210.